CXX = g++
CXXFLAGS = -g -std=c++17 -Wall -I../thirdLib/proto -I../thirdLib/net -I../thirdLib/base -I../mqCommon

LDFLAGS = -L/path/to/muduo/lib -lmuduo_net -lmuduo_base -lprotobuf -lsqlite3 -lpthread -lz

PROTO_SRCS = ../mqCommon/mq_msg.pb.cc ../mqCommon/mq_proto.pb.cc
PROTO_HDRS = ../mqCommon/mq_msg.pb.h ../mqCommon/mq_proto.pb.h
CODEC_SRC = ../thirdLib/proto/codec.cc

SRCS_common = $(PROTO_SRCS) $(CODEC_SRC)

SRCS_pc = mq_publish_client.cpp $(SRCS_common)
SRCS_cc = mq_consume_client.cpp $(SRCS_common)

OBJS_pc = $(SRCS_pc:.cpp=.o)
OBJS_pc := $(OBJS_pc:.cc=.o)

OBJS_cc = $(SRCS_cc:.cpp=.o)
OBJS_cc := $(OBJS_cc:.cc=.o)

TARGETS = pc cc

.PHONY: all clean

all: $(TARGETS)

pc: $(OBJS_pc)
	$(CXX) $(CXXFLAGS) -o $@ $^ $(LDFLAGS)

cc: $(OBJS_cc)
	$(CXX) $(CXXFLAGS) -o $@ $^ $(LDFLAGS)

%.o: %.cpp $(PROTO_HDRS)
	$(CXX) $(CXXFLAGS) -c $< -o $@
%.o: %.cc $(PROTO_HDRS)
	$(CXX) $(CXXFLAGS) -c $< -o $@

clean:
	rm -f *.o $(TARGETS)
